<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>事件委托</title>
</head>
<body>
  <ul id="wrapper">
    <li>sdfsdfs</li>
    <li>sdfsdfs</li>
    <li>sdfsdfs</li>
    <li>sdfsdfs</li>
    <li>sdfsdfs</li>
    <li>sdfsdfs</li>
    <li>sdfsdfs</li>
    <li>sdfsdfs</li>
    <li>sdfsdfs</li>
    <li>sdfsdfs</li>
    <li>sdfsdfs</li>
  </ul>
  <script>
    window.onload = function () {
      let wrapper = document.getElementById('wrapper')
      let liArr = document.getElementsByTagName('li')
      wrapper.addEventListener('click', e => {
        if (e.target.tagName.toLowerCase() === 'li') {
          for (let index in liArr) {
            if (e.target === liArr[index]) {
              // for in 获得的 下标为 String 类型的，不要忘记转换
              console.log(`${ parseInt(index) + 1 }`)
            }
          }
        }
      })
    }
  </script>
</body>
</html>
